package com.mall4j.cloud.coupon.feign;

import com.mall4j.cloud.api.coupon.bo.CouponBO;
import com.mall4j.cloud.api.coupon.dto.CouponAllocateReq;
import com.mall4j.cloud.api.coupon.dto.CouponUseReq;
import com.mall4j.cloud.api.coupon.dto.CouponUseResultDto;
import com.mall4j.cloud.api.coupon.dto.UpdateCouponOrderReq;
import com.mall4j.cloud.api.coupon.feign.CouponFeignClient;
import com.mall4j.cloud.common.response.ServerResponseEntity;
import com.mall4j.cloud.common.security.AuthUserContext;
import com.mall4j.cloud.coupon.service.UserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CouponFeignController implements CouponFeignClient {

    @Autowired
    private UserCouponService userCouponService;
    @Override
    public List<CouponBO> getUserCoupon(Long userId) {
        return userCouponService.getUserCouponBo(userId);
    }

    @Override
    public ServerResponseEntity<CouponUseResultDto> useCoupon(CouponUseReq couponUseReq) {
        return ServerResponseEntity.success(userCouponService.useCoupon(couponUseReq.getUserId(), couponUseReq));

    }

    @Override
    public ServerResponseEntity<Integer> updateCouponToUse(UpdateCouponOrderReq updateCouponOrderReq) {
        System.out.println("update coupon use ,order id=:"+updateCouponOrderReq.getOrderId());
        return ServerResponseEntity.success(userCouponService.updateCouponToUse(updateCouponOrderReq.getUserId(), updateCouponOrderReq));
    }

    @Override
    public ServerResponseEntity<Long> getCouponValueByOrderId(String orderId) {
        return ServerResponseEntity.success(userCouponService.getUserCouponValueByOrderId(orderId));
    }

    @Override
    public ServerResponseEntity<Void> allocateCoupon(CouponAllocateReq allocateReq) {

        return null;
    }
}
